<?php
namespace app\api\job;

use app\api\controller\GameNotify;
use app\common\model\Order;
use app\common\model\OrderLog;
use think\facade\Log;
use think\queue\Job;
use app\common\model\Channel;

class ChannelUploadRole {
    public function fire(Job $job, $data)
    {
        if(!empty($data['cid'])){
            if($data['cid'] == 5){
                $channel = Channel::find($data['cid']);
                $channelName = $channel['username'];
                // 动态加载自定义类（例如：app\common\CustomClass
                $className ="app\index\channel\\".$channelName; // 替换为你的类名
                if (!class_exists($className)) {
                    Log::info("渠道类初始化失败");
                }
                //自动注册
                $gameapi = new $className();
                $result = $gameapi->roleReport($data);
            }
 
        }
        $job->delete();
    }

    public function failed($data)
    {
        $order = Order::where('order_no', $data['order_no'])->find();
        $order->order_status = 4;
        $order->save();
        OrderLog::addLog($order->order_no, $order->order_status, $order->type, $order->trade_no, '通知失败');
        
        Log::error("订单：{$data['order_no']} 通知失败");
    }
}
